package com.autumn.domain.repositories.plugins;

import com.autumn.common.api.domain.entities.auditing.IGmtCreate;
import com.autumn.common.api.domain.entities.auditing.IGmtDelete;
import com.autumn.common.api.domain.entities.auditing.IGmtModified;
import com.autumn.common.api.domain.entities.auditing.ISoftDelete;
import com.autumn.mybatis.mapper.MapperInfo;

/**
 * 
 * @author xinghua 2017年12月8日 下午3:32:57
 */
public class MapperAuditingInfo {

	private final MapperInfo mapperInfo;
	private final boolean gmtCreate;
	private final boolean gmtDelete;
	private final boolean gmtModified;
	private final boolean softDelete;
	private final AuditingMethodEnum auditingMethod;
	private final String methodName;

	public MapperAuditingInfo(MapperInfo mapperInfo) {
		this.mapperInfo = mapperInfo;
		this.gmtCreate = IGmtCreate.class.isAssignableFrom(mapperInfo.getEntityClass());
		this.gmtDelete = IGmtDelete.class.isAssignableFrom(mapperInfo.getEntityClass());
		this.gmtModified = IGmtModified.class.isAssignableFrom(mapperInfo.getEntityClass());
		this.softDelete = ISoftDelete.class.isAssignableFrom(mapperInfo.getEntityClass());
		this.methodName = mapperInfo.getMethod().getName();
		AuditingMethodEnum ame = AuditingMethodEnum.forName(this.methodName);
		if (ame == null) {
			ame = AuditingMethodEnum.UN_KNOWN;
		}
		this.auditingMethod = ame;
	}

	public final MapperInfo getMapperInfo() {
		return mapperInfo;
	}

	public final boolean isGmtCreate() {
		return gmtCreate;
	}

	public final boolean isGmtDelete() {
		return gmtDelete;
	}

	public final boolean isGmtModified() {
		return gmtModified;
	}

	public final boolean isSoftDelete() {
		return softDelete;
	}

	/**
	 * 获取审计方法
	 * 
	 * @return 2017-12-11 21:03:19
	 */
	public AuditingMethodEnum getAuditingMethod() {
		return auditingMethod;
	}

}
